package com.github.aloxc.plugin.restplus.listener;

import com.github.aloxc.plugin.restplus.component.Variate;
import com.github.aloxc.plugin.restplus.component.VariateTableModel;
import com.github.aloxc.plugin.restplus.i18n.I18Bundle;
import com.github.aloxc.plugin.restplus.popup.PopupBalloon;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

public class VariateAddListener implements ActionListener {
    private Variate variate;

    public VariateAddListener(Variate variate){
        this.variate = variate;
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        VariateTableModel model = (VariateTableModel) variate.getVariateTable().getModel();
        model.addRow(new Vector(){{
            add(false);
            add("");
            add("");
            add("");
            add(false);
        }});
        variate.getTableScrollPanel().getViewport().setViewPosition(new Point(0,variate.getTableScrollPanel().getVerticalScrollBar().getMaximum()));
        variate.getVariateTable().setRowSelectionInterval(model.getRowCount() - 1,model.getRowCount() - 1);
        PopupBalloon.showPopupBalloon(variate.getVariateTable(), I18Bundle.getMessage("com.github.aloxc.plugin.restplus.setting.add.tips"));
    }
}
